package com.treehouse.sql.mysql;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import com.treehouse.logging.Logger;
import com.treehouse.sql.Database;

public class MySqlDatabase extends Database {

	private String schema = null;

	public MySqlDatabase(String name, String host, int port, String schema) {
		super(name, host, port);
		this.schema = schema;
	}

	public MySqlDatabase(String name, String host, int port, String username,
			String password, String schema) {
		super(name, host, port, username, password);
		this.schema = schema;
	}

	@Override
	protected void connect() {
		try {
			Connection con = DriverManager.getConnection("jdbc:mysql://"
					+ this.getHost() + ":" + this.getPort() + "/" + this.schema
					+ "?" + "user=" + this.getUsername() + "&" + "password="
					+ this.getPassword());
			this.setConnection(con);
		} catch (SQLException e) {
			Logger.err("Failed to open Connection to the MySQL Database "
					+ this.getHost() + ":" + this.getPort() + "/" + this.schema);
			e.printStackTrace(Logger.err);
		}
	}

}
